package com.flot.yazb.base.rxjava.fld;

import com.flot.yazb.base.client.RetrofitFactory;
import com.flot.yazb.aop.stub.RMResponse;
import com.flot.yazb.base.rxjava.RBService;
import com.flot.yazb.base.BActivity;
import com.flot.yazb.model.user.UserModel;
import com.flot.yazb.model.user.LoginParmsModel;
import com.flot.yazb.widget.utils.ToastUtil;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by fengdongfei on 2017/8/28.
 */

public class Test {

    public static void createBaseObserVer(final BActivity activity){
        LoginParmsModel prLoginModel = new LoginParmsModel();
        prLoginModel.userAccount = "v1101";
        prLoginModel.passwd = "123456";
        // Rxjava的类型接口定义,返回的是被观察者类型
        RetrofitFactory.getInstance()
                .create(RBService.UserService.class)
                .login(prLoginModel)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObserver<RMResponse<UserModel>>(new BaseImpl(){
                        @Override
                        public void dismissProgress() {
                            super.dismissProgress();
                        }

                        @Override
                        public void addRxStop(Disposable d) {
                            super.addRxStop(d);
                        }

                        @Override
                        public void addRxDestroy(Disposable d) {
                            super.addRxDestroy(d);
                        }

                        @Override
                        public void showProgress(String s) {
                            super.showProgress(s);
                        }
                    },false, activity) {
                        @Override
                        public void onSuccess(RMResponse<UserModel> response) {
                            ToastUtil.showToast(activity,"success");
                        }

                        @Override
                        public void onRelogin() {

                        }
                    });
    }
}
